
/**
 * 
 * 四向移动
 * 
 * 
 */
public class 四向移动 {
    
    public static void main(String[] args) {

        int[] originPoint = new int[]{0,0};
        int[] rightPoint = moveFace(2, originPoint);

        System.out.print("右移动x="+rightPoint[0]+"---y="+rightPoint[1]);
        System.out.println();

        int[] upPoint = moveFace(1, rightPoint);
        System.out.print("上移动x="+upPoint[0]+"---y="+upPoint[1]);
        System.out.println();

        int[] leftPoint = moveFace(0, upPoint);
        System.out.print("左移动x="+leftPoint[0]+"---y="+leftPoint[1]);
        System.out.println();

        int[] downPoint = moveFace(3, leftPoint);
        System.out.print("下移动x="+downPoint[0]+"---y="+downPoint[1]);
        System.out.println();
    }

    // i为0，1，2，3分别表示左、上、右、下四个方向
    private static int[] moveFace(int i, int[] point){

        int[] moved = new int[]{-1,0,1,0,-1};

        int[] newPoint = new int[]{point[0]+moved[i], point[1]+moved[i+1]};


        return newPoint;
    }
}
